package zjs.dc.controller;

import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;

/**
 * @Class:
 * @Author: sn
 * @Description: TODO
 * @Date: 2021/12/15 9:26
 */
public class TRecruitInfo {
    public static void main(String[] args) {
        SparkSession spark = SparkSession.builder().appName("t_recruitinfo").enableHiveSupport().getOrCreate();
        spark.sparkContext().setLogLevel("ERROR");
        Dataset<Row> zs_data = spark.sql("select * from a_dc_ep_ods.zax_t_recruit");
        long zs_count = zs_data.count();
        if(zs_count>0) {
            //获取招聘信息的增量数据
            spark.sql("select \n" +
                    "s.uid,\n" +
                    "s.eid,\n" +
                    "s.city,\n" +
                    "s.employ_type,\n" +
                    "s.ent_name,\n" +
                    "s.description,\n" +
                    "s.district,\n" +
                    "s.education,\n" +
                    "s.employer_number,\n" +
                    "s.expiry_date,\n" +
                    "s.experience,\n" +
                    "s.location,\n" +
                    "s.ori_salary,\n" +
                    "s.ori_salary_left,\n" +
                    "s.ori_salary_right,\n" +
                    "s.start_date,\n" +
                    "s.title,\n" +
                    "s.create_time,\n" +
                    "s.update_time,\n" +
                    "s.data_state,\n" +
                    "x.credit_code \n" +
                    "from a_dc_ep_ods.zax_t_recruit s \n" +
                    "inner join (select * from  a_dc_ep_dwi.zax_t_base where ent_name is not null ) x on s.eid = x.uid \n" +
                    "where s.data_state != 1").createOrReplaceTempView("t_recruitinfo_temp");


            spark.sql("select a.key_no,a.company_id, translate(translate(a.company_name,'（','('),'）',')') as company_name  from (select aa.*,ROW_NUMBER() OVER(PARTITION BY aa.company_name ORDER BY aa.dates DESC,aa.isadd DESC) num from a_dc_ep_ods.t_eci_company aa) a").createOrReplaceTempView("t_eci_company_temp");

            //获取新增，修改，删除招聘信息数据
            spark.sql("select \n" +
                    "s.uid  as id,\n" +
                    "(case when x.key_no !=''  then x.key_no else s.eid end ) as key_no,\n" +
                    "(case when x.company_id !=''  then x.company_id else s.eid end ) as company_id,\n" +
                    "(case when x.company_name !=''  then x.company_name else s.ent_name end ) as company_name,\n" +
                    "s.uid as recruit_id,\n" +
                    "s.title,\n" +
                    "'zax' as source,\n" +
                    "s.city as area,\n" +
                    "s.ori_salary as salary,\n" +
                    "'无' as url,\n" +
                    "s.start_date as publish_time,\n" +
                    "s.description,\n" +
                    "s.education,\n" +
                    "s.experience,\n" +
                    "s.employer_number as number,\n" +
                    "date_format(s.update_time,'yyyyMMdd') as dates,\n" +
                    "(case when s.data_state ='2'  then '-1' else s.data_state end ) as isadd\n" +
                    "from  t_recruitinfo_temp s\n" +
                    "inner join t_eci_company_temp  x ON  trim(s.ent_name)= trim(x.company_name) ").createOrReplaceTempView("t_recruitinfo_end");

            spark.sql("insert overwrite table a_dc_ep_incr.t_recruitinfo select * from t_recruitinfo_end");
        }else{
            spark.sql("TRUNCATE TABLE a_dc_ep_incr.t_recruitinfo");
            System.out.println("智侒信本期没有招聘数据");
        }
        spark.stop();
    }
}
